package qdu.edu.com.fushanf4.item_desc_dataset.txt.distinct;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class ProductDistinctMapper extends Mapper <LongWritable, Text, Text, NullWritable>{
    private final Text keyOut = new Text();
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] split = line.split("\t");

        if (split.length <= 1) {    // 防止不干净的数据导致数组越界，有些数据可能并不符合一本性的规则，导致出人意料的结果
            return;
        }

        keyOut.set(split[0]);
        context.write(keyOut, NullWritable.get());
    }
}
